Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 681)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 12.97556 12.97454 12.97354 12.97255 12.97156 12.97059 12.96962 12.96865
## [9] 12.96769 12.96672 12.96575 12.96477 12.96378 12.96279 12.96178 12.96075
## [17] 12.95971 12.95865 12.95757 12.95646 12.95533 12.95417 12.95297 12.95175
## [25] 12.95049 12.94919 12.94785 12.94647 12.94505 12.94358 12.94206 12.94049
## [33] 12.93887 12.93719 12.93545 12.93366 12.93179 12.92982 12.92778 12.92566
## [41] 12.92346 12.92121 12.91889 12.91652 12.91411 12.91166 12.90917 12.90666
## [49] 12.90413 12.90158 12.89902 12.89646 12.89391 12.89136 12.88883 12.88633
## [57] 12.88385 12.88141 12.87900 12.87665 12.87435 12.87211 12.86993 12.86783
## [65] 12.86580 12.86386 12.86201 12.86026 12.85861 12.85707 12.85564 12.85409
## [73] 12.85217 12.84990 12.84731 12.84442 12.84124 12.83779 12.83411 12.83019
## [81] 12.82608 12.82178 12.81732 12.81271 12.80798 12.80315 12.79824 12.79326
## [89] 12.78825 12.78321 12.77817 12.77315 12.76817 12.76324 12.75840 12.75366
## [97] 12.74903 12.74455 12.74023 12.73609 12.73214 12.72842 12.72495 12.72173
## [105] 12.71879 12.71616 12.71385 12.71188 12.71028 12.70905 12.70823 12.70784
## [113] 12.70788 12.70826 12.70883 12.70961 12.71059 12.71176 12.71314 12.71473
## [121] 12.71651 12.71851 12.72070 12.72311 12.72572 12.72854 12.73157 12.73481
## [129] 12.73827 12.74193 12.74580 12.74989 12.75420 12.75871 12.76345 12.76840
## [137] 12.77357 12.77895 12.78456 12.79038 12.79759 12.80717 12.81890 12.83253
## [145] 12.84782 12.86453 12.88243 12.90127 12.92082 12.94083 12.96107 12.98130
## [153] 13.00127 13.02076 13.03951 13.05730 13.07387 13.08900 13.10245 13.11396
## [161] 13.12332 13.13256 13.14375 13.15665 13.17105 13.18670 13.20337 13.22084
## [169] 13.23887 13.25723 13.27570 13.29403 13.31200 13.32938 13.34594 13.36144
## [177] 13.37565 13.38835 13.39930 13.40827 13.41504 13.41936 13.42256 13.42606
## [185] 13.42977 13.43359 13.43745 13.44125 13.44489 13.44830 13.45139 13.45405
## [193] 13.45621 13.45778 13.45866 13.45878 13.45802 13.45632 13.45358 13.44971
## [201] 13.44462 13.43822 13.43043 13.42115 13.41030 13.39707 13.38094 13.36217
## [209] 13.34104 13.31783 13.29283 13.26630 13.23854 13.20981 13.18041 13.15060
## [217] 13.12066 13.09089 13.06154 13.03291 13.00528 12.97891 12.95410 12.93112
## [225] 12.90717 12.87955 12.84864 12.81484 12.77855 12.74015 12.70004 12.65862
## [233] 12.61627 12.57340 12.53039 12.48764 12.44554 12.40449 12.36487 12.32709
## [241] 12.29154 12.25861 12.22869 12.20218 12.17947 12.15926 12.13995 12.12148
## [249] 12.10381 12.08688 12.07066 12.05508 12.04011 12.02568 12.01176 11.99828
## [257] 11.98521 11.97250 11.96008 11.94792 11.93597 11.92572 11.91849 11.91396
## [265] 11.91182 11.91173 11.91338 11.91644 11.92060 11.92553 11.93091 11.93642
## [273] 11.94174 11.94654 11.95051 11.95333 11.95466 11.95419 11.95161 11.94658
## [281] 11.94099 11.93679 11.93377 11.93174 11.93047 11.92978 11.92944 11.92926
## [289] 11.92902 11.92852 11.92755 11.92591 11.92338 11.91977 11.91487 11.90846
## [297] 11.90100 11.89307 11.88473 11.87600 11.86692 11.85753 11.84786 11.83794
## [305] 11.82782 11.81752 11.80709 11.79655 11.78595 11.77532 11.76470 11.75411
## [313] 11.74360 11.73321 11.72295 11.71289 11.70304 11.69143 11.67636 11.65823
## [321] 11.63746 11.61449 11.58971 11.56357 11.53646 11.50882 11.48106 11.45361
## [329] 11.42688 11.40128 11.37725 11.35520 11.33555 11.31871 11.30512 11.29518
## [337] 11.28931 11.28501 11.27966 11.27354 11.26691 11.26005 11.25324 11.24676
## [345] 11.24087 11.23585 11.23197 11.22952 11.22876 11.22997 11.23343 11.23940
## [353] 11.24818 11.25973 11.27381 11.29019 11.30864 11.32894 11.35086 11.37416
## [361] 11.39861 11.42398 11.45005 11.47658 11.50335 11.53012 11.55667 11.58275
## [369] 11.60816 11.63264 11.65599 11.67795 11.70101 11.72756 11.75725 11.78975
## [377] 11.82470 11.86177 11.90062 11.94090 11.98226 12.02437 12.06689 12.10946
## [385] 12.15175 12.19342 12.23412 12.27351 12.31124 12.34698 12.38038 12.41109
## [393] 12.43879 12.46311 12.48684 12.51277 12.54056 12.56988 12.60041 12.63181
## [401] 12.66375 12.69590 12.72794 12.75954 12.79035 12.82006 12.84834 12.87484
## [409] 12.89925 12.92124 12.94047 12.95661 12.96934 12.97914 12.98685 12.99265
## [417] 12.99672 12.99925 13.00042 13.00042 12.99943 12.99762 12.99519 12.99233
## [425] 12.98920 12.98600 12.98292 12.98012 12.97781 12.97408 12.96714 12.95732
## [433] 12.94494 12.93034 12.91383 12.89574 12.87640 12.85614 12.83528 12.81414
## [441] 12.79307 12.77237 12.75237 12.73342 12.71582 12.69990 12.68600 12.67444
## [449] 12.66296 12.64926 12.63357 12.61614 12.59721 12.57701 12.55579 12.53378
## [457] 12.51123 12.48837 12.46545 12.44270 12.42036 12.39868 12.37789 12.35823
## [465] 12.33995 12.32327 12.30845 12.29573 12.28533 12.27600 12.26638 12.25655
## [473] 12.24662 12.23666 12.22678 12.21707 12.20762 12.19852 12.18986 12.18173
## [481] 12.17424 12.16747 12.16150 12.15645 12.15239 12.14917 12.14656 12.14454
## [489] 12.14310 12.14224 12.14192 12.14214 12.14288 12.14414 12.14589 12.14812
## [497] 12.15081 12.15396 12.15755 12.16156 12.16599 12.17080 12.17600 12.18157
## [505] 12.18843 12.19739 12.20823 12.22076 12.23476 12.25005 12.26641 12.28364
## [513] 12.30154 12.31990 12.33852 12.35719 12.37571 12.39389 12.41151 12.42836
## [521] 12.44426 12.45899 12.47235 12.48413 12.49414 12.50411 12.51583 12.52912
## [529] 12.54382 12.55976 12.57677 12.59468 12.61332 12.63253 12.65213 12.67196
## [537] 12.69186 12.71164 12.73115 12.75021 12.76866 12.78633 12.80305 12.81865
## [545] 12.83297 12.84583 12.85706 12.86651 12.87400 12.87936 12.88242 12.88302
## [553] 12.88099 12.87702 12.87196 12.86588 12.85884 12.85090 12.84214 12.83262
## [561] 12.82240 12.81156 12.80014 12.78823 12.77588 12.76316 12.75014 12.73689
## [569] 12.72346 12.70759 12.68729 12.66306 12.63536 12.60468 12.57150 12.53630
## [577] 12.49957 12.46177 12.42340 12.38494 12.34686 12.30964 12.27378 12.23975
## [585] 12.20802 12.17909 12.15343 12.13152 12.10894 12.08143 12.04974 12.01462
## [593] 11.97681 11.93707 11.89614 11.85477 11.81372 11.77371 11.73552 11.69988
## [601] 11.66754 11.63925 11.61576 11.59781 11.58373 11.57125 11.56030 11.55076
## [609] 11.54256 11.53560 11.52977 11.52500 11.52119 11.51823 11.51605 11.51454
## [617] 11.51361 11.51317 11.51313 11.51338 11.51384 11.51442 11.51502 11.51554
## [625] 11.51589 11.51653 11.51795 11.52014 11.52310 11.52680 11.53123 11.53639
## [633] 11.54226 11.54883 11.55608 11.56400 11.57259 11.58182 11.59169 11.60218
## [641] 11.61327 11.62497 11.63725 11.65010 11.66361 11.67784 11.69280 11.70847
## [649] 11.72484 11.74191 11.75966 11.77808 11.79717 11.81691 11.83730 11.85832
## [657] 11.87997 11.90223 11.92510 11.94857 11.97261 11.99720 12.02234 12.04805
## [665] 12.07433 12.10119 12.12863 12.15665 12.18528 12.21450 12.24434 12.27479
## [673] 12.30586 12.33757 12.36990 12.40288 12.43651 12.47079 12.50573 12.54134
## [681] 12.57762
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 681)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.60801 12.60429 12.60066 12.59711 12.59365 12.59027 12.58698 12.58376
## [9] 12.58062 12.57755 12.57456 12.57163 12.56878 12.56600 12.56328 12.56062
## [17] 12.55803 12.55549 12.55302 12.55060 12.54823 12.54592 12.54366 12.54145
## [25] 12.53928 12.53716 12.53508 12.53305 12.53105 12.52909 12.52717 12.52528
## [33] 12.52342 12.52160 12.51980 12.51803 12.51625 12.51446 12.51265 12.51082
## [41] 12.50900 12.50717 12.50535 12.50355 12.50177 12.50001 12.49829 12.49661
## [49] 12.49497 12.49338 12.49185 12.49039 12.48900 12.48768 12.48644 12.48530
## [57] 12.48425 12.48330 12.48246 12.48173 12.48112 12.48064 12.48029 12.48008
## [65] 12.48002 12.48011 12.48035 12.48076 12.48134 12.48209 12.48303 12.48407
## [73] 12.48513 12.48623 12.48735 12.48850 12.48970 12.49093 12.49220 12.49352
## [81] 12.49489 12.49631 12.49778 12.49932 12.50091 12.50257 12.50430 12.50610
## [89] 12.50797 12.50992 12.51196 12.51407 12.51627 12.51856 12.52094 12.52342
## [97] 12.52600 12.52868 12.53147 12.53436 12.53737 12.54049 12.54373 12.54709
## [105] 12.55057 12.55418 12.55792 12.56180 12.56581 12.56996 12.57426 12.57870
## [113] 12.58329 12.58781 12.59205 12.59606 12.59986 12.60349 12.60700 12.61041
## [121] 12.61375 12.61708 12.62041 12.62380 12.62726 12.63084 12.63458 12.63851
## [129] 12.64266 12.64707 12.65178 12.65682 12.66223 12.66804 12.67430 12.68203
## [137] 12.69213 12.70436 12.71849 12.73429 12.75155 12.77002 12.78949 12.80972
## [145] 12.83049 12.85157 12.87273 12.89375 12.91440 12.93445 12.95367 12.97183
## [153] 12.98872 13.00409 13.01773 13.02940 13.04164 13.05685 13.07466 13.09469
## [161] 13.11656 13.13989 13.16430 13.18941 13.21484 13.24020 13.26513 13.28923
## [169] 13.31213 13.33345 13.35281 13.36982 13.38412 13.39531 13.40302 13.40862
## [177] 13.41373 13.41833 13.42242 13.42596 13.42895 13.43136 13.43320 13.43443
## [185] 13.43504 13.43502 13.43435 13.43301 13.43099 13.42828 13.42485 13.42069
## [193] 13.41579 13.41013 13.40369 13.39645 13.38841 13.37955 13.36984 13.35928
## [201] 13.34785 13.33553 13.32230 13.30816 13.29132 13.27041 13.24598 13.21860
## [209] 13.18882 13.15722 13.12435 13.09077 13.05706 13.02376 12.99144 12.96067
## [217] 12.93201 12.90601 12.88325 12.86043 12.83417 12.80483 12.77279 12.73842
## [225] 12.70212 12.66424 12.62517 12.58529 12.54498 12.50460 12.46454 12.42518
## [233] 12.38689 12.35004 12.31502 12.28221 12.25197 12.22469 12.20075 12.18051
## [241] 12.16282 12.14623 12.13068 12.11609 12.10240 12.08956 12.07751 12.06617
## [249] 12.05548 12.04539 12.03582 12.02672 12.01803 12.00967 12.00160 11.99374
## [257] 11.98603 11.97841 11.97082 11.96513 11.96298 11.96392 11.96751 11.97330
## [265] 11.98085 11.98971 11.99944 12.00960 12.01974 12.02942 12.03819 12.04561
## [273] 12.05124 12.05463 12.05533 12.05608 12.05964 12.06566 12.07378 12.08366
## [281] 12.09492 12.10721 12.12018 12.13347 12.14672 12.15958 12.17168 12.18268
## [289] 12.19221 12.19992 12.20545 12.20844 12.20854 12.20539 12.19955 12.19195
## [297] 12.18273 12.17204 12.16005 12.14690 12.13276 12.11777 12.10209 12.08587
## [305] 12.06928 12.05246 12.03556 12.01875 12.00217 11.98599 11.97035 11.95542
## [313] 11.94134 11.92826 11.91636 11.90274 11.88485 11.86332 11.83877 11.81182
## [321] 11.78309 11.75322 11.72283 11.69254 11.66297 11.63475 11.60850 11.58485
## [329] 11.56443 11.54785 11.53574 11.52521 11.51310 11.49969 11.48523 11.47001
## [337] 11.45427 11.43829 11.42234 11.40667 11.39156 11.37727 11.36406 11.35221
## [345] 11.34197 11.33361 11.32741 11.32362 11.32250 11.32434 11.32888 11.33558
## [353] 11.34424 11.35467 11.36666 11.38002 11.39455 11.41005 11.42632 11.44316
## [361] 11.46038 11.47778 11.49515 11.51230 11.52903 11.54515 11.56253 11.58302
## [369] 11.60637 11.63236 11.66073 11.69125 11.72367 11.75776 11.79326 11.82995
## [377] 11.86758 11.90591 11.94469 11.98369 12.02266 12.06137 12.09957 12.13702
## [385] 12.17348 12.20871 12.24247 12.27451 12.30460 12.33250 12.35795 12.38073
## [393] 12.40322 12.42773 12.45393 12.48147 12.50999 12.53916 12.56862 12.59804
## [401] 12.62706 12.65534 12.68253 12.70829 12.73226 12.75411 12.77349 12.79005
## [409] 12.80514 12.82029 12.83542 12.85046 12.86531 12.87992 12.89418 12.90804
## [417] 12.92140 12.93420 12.94635 12.95777 12.96839 12.97812 12.98689 12.99461
## [425] 13.00122 13.00663 13.01077 13.01354 13.01489 13.01416 13.01092 13.00540
## [433] 12.99780 12.98835 12.97727 12.96477 12.95109 12.93642 12.92100 12.90505
## [441] 12.88878 12.87241 12.85616 12.84026 12.82491 12.81035 12.79678 12.78443
## [449] 12.77112 12.75474 12.73562 12.71408 12.69045 12.66505 12.63821 12.61025
## [457] 12.58150 12.55229 12.52293 12.49376 12.46511 12.43728 12.41062 12.38545
## [465] 12.36209 12.34086 12.32210 12.30613 12.29327 12.28091 12.26647 12.25031
## [473] 12.23280 12.21429 12.19515 12.17573 12.15641 12.13754 12.11949 12.10261
## [481] 12.08727 12.07384 12.06266 12.05412 12.04855 12.04481 12.04146 12.03855
## [489] 12.03610 12.03414 12.03268 12.03176 12.03140 12.03162 12.03245 12.03392
## [497] 12.03605 12.03886 12.04239 12.04665 12.05167 12.05748 12.06410 12.07156
## [505] 12.08127 12.09441 12.11066 12.12968 12.15116 12.17476 12.20018 12.22707
## [513] 12.25512 12.28400 12.31339 12.34295 12.37238 12.40133 12.42950 12.45654
## [521] 12.48215 12.50599 12.52773 12.54706 12.56365 12.58000 12.59870 12.61951
## [529] 12.64223 12.66662 12.69246 12.71955 12.74764 12.77653 12.80599 12.83579
## [537] 12.86573 12.89557 12.92510 12.95410 12.98233 13.00959 13.03565 13.06028
## [545] 13.08328 13.10441 13.12345 13.14019 13.15441 13.16587 13.17436 13.17966
## [553] 13.18155 13.18071 13.17805 13.17372 13.16786 13.16060 13.15207 13.14243
## [561] 13.13180 13.12032 13.10814 13.09538 13.08220 13.06871 13.05508 13.04142
## [569] 13.02789 13.01237 12.99297 12.97007 12.94407 12.91537 12.88437 12.85148
## [577] 12.81708 12.78159 12.74539 12.70888 12.67248 12.63657 12.60155 12.56783
## [585] 12.53580 12.50586 12.47842 12.45386 12.42787 12.39639 12.36023 12.32019
## [593] 12.27707 12.23168 12.18482 12.13730 12.08992 12.04349 11.99881 11.95668
## [601] 11.91791 11.88330 11.85365 11.82978 11.80925 11.78912 11.76943 11.75023
## [609] 11.73156 11.71347 11.69600 11.67920 11.66310 11.64777 11.63323 11.61953
## [617] 11.60672 11.59484 11.58394 11.57406 11.56525 11.55754 11.55099 11.54563
## [625] 11.54152 11.53836 11.53585 11.53400 11.53285 11.53242 11.53272 11.53378
## [633] 11.53562 11.53827 11.54174 11.54607 11.55127 11.55736 11.56437 11.57232
## [641] 11.58124 11.59114 11.60205 11.61399 11.62684 11.64049 11.65494 11.67021
## [649] 11.68630 11.70322 11.72098 11.73960 11.75909 11.77945 11.80070 11.82284
## [657] 11.84589 11.86986 11.89476 11.92059 11.94736 11.97504 12.00364 12.03315
## [665] 12.06356 12.09488 12.12709 12.16020 12.19420 12.22908 12.26484 12.30147
## [673] 12.33898 12.37736 12.41661 12.45671 12.49767 12.53948 12.58214 12.62564
## [681] 12.66998
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 681)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 11.95102 11.94940 11.94782 11.94627 11.94475 11.94325 11.94177 11.94031
## [9] 11.93886 11.93743 11.93600 11.93458 11.93316 11.93174 11.93032 11.92889
## [17] 11.92745 11.92600 11.92453 11.92304 11.92153 11.92000 11.91843 11.91683
## [25] 11.91520 11.91353 11.91182 11.91007 11.90827 11.90642 11.90451 11.90255
## [33] 11.90053 11.89844 11.89629 11.89408 11.89178 11.88942 11.88697 11.88445
## [41] 11.88184 11.87914 11.87635 11.87342 11.87029 11.86699 11.86352 11.85991
## [49] 11.85617 11.85231 11.84834 11.84429 11.84016 11.83597 11.83174 11.82747
## [57] 11.82319 11.81891 11.81464 11.81040 11.80621 11.80206 11.79799 11.79401
## [65] 11.79013 11.78636 11.78272 11.77922 11.77589 11.77273 11.76975 11.76698
## [73] 11.76442 11.76210 11.76002 11.75821 11.75667 11.75541 11.75406 11.75222
## [81] 11.74992 11.74721 11.74411 11.74066 11.73689 11.73283 11.72853 11.72400
## [89] 11.71929 11.71442 11.70944 11.70437 11.69925 11.69411 11.68898 11.68390
## [97] 11.67890 11.67402 11.66928 11.66473 11.66039 11.65630 11.65249 11.64899
## [105] 11.64584 11.64308 11.64072 11.63882 11.63740 11.63649 11.63613 11.63635
## [113] 11.63718 11.63867 11.64083 11.64371 11.64734 11.65175 11.65697 11.66304
## [121] 11.67061 11.68018 11.69156 11.70459 11.71908 11.73486 11.75173 11.76953
## [129] 11.78807 11.80718 11.82667 11.84637 11.86609 11.88565 11.90488 11.92360
## [137] 11.94162 11.95878 11.97488 11.98974 12.00568 12.02490 12.04707 12.07186
## [145] 12.09894 12.12799 12.15867 12.19065 12.22362 12.25723 12.29117 12.32510
## [153] 12.35869 12.39161 12.42355 12.45416 12.48312 12.51010 12.53477 12.55680
## [161] 12.57587 12.59424 12.61425 12.63568 12.65829 12.68185 12.70616 12.73097
## [169] 12.75606 12.78121 12.80619 12.83078 12.85474 12.87785 12.89989 12.92064
## [177] 12.93985 12.95732 12.97281 12.98609 12.99695 13.00515 13.01195 13.01871
## [185] 13.02534 13.03178 13.03793 13.04372 13.04907 13.05390 13.05813 13.06169
## [193] 13.06448 13.06644 13.06748 13.06753 13.06650 13.06432 13.06090 13.05617
## [201] 13.05005 13.04246 13.03331 13.02254 13.01005 12.99419 12.97366 12.94895
## [209] 12.92055 12.88896 12.85466 12.81815 12.77991 12.74044 12.70023 12.65976
## [217] 12.61954 12.58004 12.54176 12.50518 12.47081 12.43914 12.41064 12.38581
## [225] 12.36136 12.33389 12.30374 12.27126 12.23678 12.20065 12.16321 12.12480
## [233] 12.08578 12.04647 12.00722 11.96838 11.93028 11.89328 11.85770 11.82390
## [241] 11.79222 11.76299 11.73657 11.71329 11.69350 11.67630 11.66049 11.64592
## [249] 11.63247 11.61999 11.60836 11.59744 11.58709 11.57719 11.56758 11.55815
## [257] 11.54875 11.53925 11.52952 11.51941 11.50880 11.49966 11.49382 11.49092
## [265] 11.49061 11.49253 11.49635 11.50170 11.50823 11.51560 11.52344 11.53141
## [273] 11.53916 11.54633 11.55256 11.55752 11.56085 11.56218 11.56119 11.55750
## [281] 11.55369 11.55232 11.55302 11.55544 11.55920 11.56394 11.56930 11.57492
## [289] 11.58042 11.58544 11.58963 11.59261 11.59402 11.59350 11.59069 11.58521
## [297] 11.57679 11.56559 11.55190 11.53598 11.51813 11.49863 11.47776 11.45580
## [305] 11.43302 11.40973 11.38619 11.36269 11.33951 11.31693 11.29524 11.27471
## [313] 11.25563 11.23829 11.22295 11.20991 11.19945 11.18908 11.17634 11.16155
## [321] 11.14501 11.12705 11.10796 11.08806 11.06766 11.04707 11.02661 11.00658
## [329] 10.98730 10.96908 10.95223 10.93706 10.92388 10.91300 10.90474 10.89940
## [337] 10.89730 10.89772 10.89967 10.90302 10.90765 10.91345 10.92028 10.92804
## [345] 10.93659 10.94582 10.95560 10.96582 10.97636 10.98709 10.99790 11.00865
## [353] 11.02074 11.03546 11.05258 11.07185 11.09303 11.11588 11.14016 11.16564
## [361] 11.19207 11.21921 11.24682 11.27466 11.30250 11.33009 11.35718 11.38355
## [369] 11.40895 11.43314 11.45588 11.47693 11.49815 11.52141 11.54651 11.57324
## [377] 11.60138 11.63073 11.66108 11.69222 11.72393 11.75602 11.78826 11.82046
## [385] 11.85240 11.88387 11.91466 11.94456 11.97337 12.00087 12.02686 12.05112
## [393] 12.07345 12.09363 12.11337 12.13436 12.15641 12.17931 12.20287 12.22689
## [401] 12.25117 12.27551 12.29970 12.32356 12.34687 12.36944 12.39107 12.41157
## [409] 12.43072 12.44833 12.46421 12.47815 12.48995 12.50029 12.51000 12.51908
## [417] 12.52754 12.53537 12.54259 12.54919 12.55518 12.56058 12.56537 12.56957
## [425] 12.57318 12.57620 12.57864 12.58051 12.58180 12.58161 12.57915 12.57465
## [433] 12.56832 12.56037 12.55103 12.54050 12.52901 12.51676 12.50399 12.49089
## [441] 12.47769 12.46461 12.45185 12.43964 12.42820 12.41773 12.40845 12.40058
## [449] 12.39260 12.38294 12.37178 12.35928 12.34560 12.33092 12.31539 12.29919
## [457] 12.28248 12.26542 12.24819 12.23095 12.21386 12.19710 12.18082 12.16519
## [465] 12.15039 12.13657 12.12391 12.11256 12.10270 12.09301 12.08216 12.07037
## [473] 12.05781 12.04468 12.03117 12.01747 12.00377 11.99026 11.97713 11.96456
## [481] 11.95276 11.94191 11.93221 11.92383 11.91698 11.91063 11.90371 11.89634
## [489] 11.88864 11.88075 11.87278 11.86486 11.85711 11.84966 11.84263 11.83614
## [497] 11.83032 11.82529 11.82117 11.81810 11.81618 11.81556 11.81634 11.81866
## [505] 11.82252 11.82779 11.83436 11.84211 11.85094 11.86074 11.87141 11.88282
## [513] 11.89488 11.90747 11.92049 11.93382 11.94737 11.96101 11.97465 11.98817
## [521] 12.00146 12.01442 12.02693 12.03889 12.05019 12.06250 12.07742 12.09473
## [529] 12.11421 12.13565 12.15881 12.18349 12.20946 12.23651 12.26442 12.29296
## [537] 12.32192 12.35108 12.38021 12.40911 12.43755 12.46531 12.49217 12.51792
## [545] 12.54233 12.56518 12.58626 12.60535 12.62222 12.63667 12.64846 12.65738
## [553] 12.66321 12.66728 12.67103 12.67442 12.67740 12.67996 12.68203 12.68360
## [561] 12.68461 12.68504 12.68484 12.68397 12.68239 12.68008 12.67698 12.67306
## [569] 12.66829 12.66128 12.65090 12.63750 12.62140 12.60296 12.58252 12.56040
## [577] 12.53696 12.51252 12.48744 12.46204 12.43668 12.41168 12.38739 12.36415
## [585] 12.34230 12.32217 12.30411 12.28846 12.27161 12.25018 12.22481 12.19617
## [593] 12.16489 12.13165 12.09709 12.06187 12.02664 11.99205 11.95876 11.92743
## [601] 11.89870 11.87323 11.85167 11.83468 11.82037 11.80643 11.79288 11.77975
## [609] 11.76705 11.75482 11.74308 11.73184 11.72114 11.71100 11.70143 11.69247
## [617] 11.68414 11.67645 11.66944 11.66313 11.65754 11.65269 11.64861 11.64531
## [625] 11.64284 11.64107 11.63989 11.63930 11.63930 11.63988 11.64104 11.64278
## [633] 11.64510 11.64799 11.65145 11.65548 11.66008 11.66524 11.67097 11.67725
## [641] 11.68410 11.69149 11.69945 11.70795 11.71701 11.72661 11.73678 11.74750
## [649] 11.75877 11.77062 11.78302 11.79599 11.80953 11.82365 11.83833 11.85359
## [657] 11.86944 11.88586 11.90286 11.92045 11.93862 11.95733 11.97660 11.99643
## [665] 12.01681 12.03775 12.05925 12.08131 12.10393 12.12711 12.15085 12.17516
## [673] 12.20003 12.22546 12.25146 12.27803 12.30516 12.33286 12.36113 12.38998
## [681] 12.41939
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")